package com.noble.meether.mail.ui.friend.request;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.noble.meether.R;
import com.noble.glamour.module.logic.baseui.custom.ViewGroupPagerAdapter;
import com.noble.library.base.BaseAppCompatActivity;
import com.noble.library.controls.smarttablayout.PagerItem;
import com.noble.library.controls.smarttablayout.SmartTabLayout;
import com.noble.library.view.base.BasePanel;

import java.util.ArrayList;
import java.util.List;

/**
 * 好友申请
 */
public class MyFriendRequestAct extends BaseAppCompatActivity {
    private ViewPager vpViewChange;
    private List<PagerItem> listViews;//pagerItem集合
    private List<BasePanel> panels = new ArrayList<>(); // Tab页面列表

    private FriendRequestPanel requestPanel;
    private FriendMyRequestPanel myRequestPanel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_invite_layout);
        initView();
    }

    private void initView() {
        setBackView();
        View titleCenter = LayoutInflater.from(this).inflate(R.layout.act_invite_title, null);
        setTitleCenterContainer(titleCenter);

        SmartTabLayout stlTitles = titleCenter.findViewById(R.id.stl_titles);
        vpViewChange = findViewById(R.id.viewpager);
        initViewsList();
        initViewPager();
        ((LinearLayout) stlTitles.getTabStrip()).setGravity(Gravity.CENTER_HORIZONTAL);//标题居中
        stlTitles.setViewPager(vpViewChange);//设置viewpager
        stlTitles.setOnPageChangeListener(null);
    }

    /**
     * 添加展示panel
     */
    private void initViewsList() {
        listViews = new ArrayList<>();
        requestPanel = new FriendRequestPanel(this);
        myRequestPanel = new FriendMyRequestPanel(this);

        panels.add(requestPanel);
        panels.add(myRequestPanel);
        listViews.add(new PagerItem("申请列表", panels.get(0).getContentView()));
        listViews.add(new PagerItem("我的申请", panels.get(1).getContentView()));
    }

    private void initViewPager() {
        vpViewChange.setAdapter(new ViewGroupPagerAdapter(listViews));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (requestPanel != null)
            requestPanel.release();
        if (myRequestPanel != null)
            myRequestPanel.release();
    }
}